package com.talent.jiwen.util;

import android.content.Context;
import android.content.SharedPreferences;

import com.talent.jiwen.base.App;

public class SPUtil {

    private static SharedPreferences sp = App.getInstance().getSharedPreferences("SPU", Context.MODE_PRIVATE);
    private static SharedPreferences spNoDelete = App.getInstance().getSharedPreferences("SPUNOTDELETE", Context.MODE_PRIVATE);

    /**
     * 退出登录不清除的数据
     * @param name
     * @param value
     */
    public static void stringDataIn(String name, String value){
        SharedPreferences.Editor edit = spNoDelete.edit();
        edit.putString(name,value);
        edit.commit();
    }

    /**
     * 退出登录不清除的数据
     * @param name
     */
    public static String stringDataOut(String name){
        return spNoDelete.getString(name,null);
    }


    public static void booleanDataIn(String name, boolean value){
        SharedPreferences.Editor edit = spNoDelete.edit();
        edit.putBoolean(name,value);
        edit.commit();
    }

    //取数据
    public static boolean booleanDataOut(String name){
        return spNoDelete.getBoolean(name , false);
    }

    public static void stringIn(String name, String value){
        SharedPreferences.Editor edit = sp.edit();
        edit.putString(name,value);
        edit.commit();
    }
    //取数据
    public static String stringOut(String name){
        return sp.getString(name,null);
    }
    //清除数据
    public static void  stringClear(String name){
        SharedPreferences.Editor editor = sp.edit();
        editor.remove(name);
        editor.commit();
    }


    public static void intIn(String name, int value){
        SharedPreferences.Editor edit = sp.edit();
        edit.putInt(name,value);
        edit.commit();
    }

    public static void booleanIn(String name, boolean value){
        SharedPreferences.Editor edit = sp.edit();
        edit.putBoolean(name,value);
        edit.commit();
    }

    //取数据
    public static boolean booleanOut(String name){
        return sp.getBoolean(name , false);
    }

    //取数据
    public static int intOut(String name){
        return sp.getInt(name,0);
    }

    public static void clearAll(){
        sp.edit().clear().commit();
    }

    public static void clearDataAll(){
        spNoDelete.edit().clear().commit();
    }


    public static String getUserId(){
        return stringOut(SPConstant.USER_ID);
    }
    public static String getUserHeadImg(){
        return stringOut(SPConstant.USER_HEAD_URL);
    }

    public static String getBSUId(){
        return "s"+stringOut(SPConstant.USER_ID);
    }

    public static String getUserName(){
        return stringOut(SPConstant.USER_NAME);
    }

    public static String getToken(){
        return stringOut(SPConstant.TOKEN);
    }

    public static String getBSToken(){
        return stringOut(SPConstant.NIM_TOKEN);
    }

    public static String getUserPhone(){
        return stringOut(SPConstant.PHONE);
    }

    public static int getIDCardBindStatus(){
        return intOut(SPConstant.ID_CARD_BIND_STATUS);
    }

    public static String getTotalAmount(){
        return stringOut(SPConstant.TOTAL_AMOUNT);
    }



}
